package org.ezplatform.office.questionnaire.dao;

import java.util.List;

import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.questionnaire.entity.QuestionnaireSetTopic;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository("questionnaireSetTopicDao")
public interface QuestionnaireSetTopicDao extends JpaBaseDao<QuestionnaireSetTopic,String>{
	
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_questionnaire_set_topic where set_id =?1")
	int deleteTopicBySetId(String setId);
	
	@Modifying
	@Query(nativeQuery = true, value = "delete from oa_questionnaire_set_topic where set_id in (?1)")
	int deleteTopicBySetId(List<String> list);
	
	@Query("Select id from QuestionnaireSetTopic where setId = ?1")
	List<String> getTopicIdBySetId(String setId);
	
	@Query("Select id from QuestionnaireSetTopic where setId in (?1)")
	List<String> getTopicIdBySetId(List<String> list);
	
	@Query("from QuestionnaireSetTopic where setId = ?1 order by topicNo")
	List<QuestionnaireSetTopic> getTopicBySetId(String setId);
	
	@Query("from QuestionnaireSetTopic where setId = ?1 and topicType = ?2 order by topicNo")
	List<QuestionnaireSetTopic> getTopicBySetIdAndTopicType(String setId, String topicType);
	
	@Query("from QuestionnaireSetTopic where setId = ?1 and topicType = ?2 and topicNameTxt like '%?3%' order by topicNo")
	List<QuestionnaireSetTopic> getTopicBySetIdAndTopicTypeAndTopicName(String setId, String topicType, String topicName);

	@Query("from QuestionnaireSetTopic where topicType = ?1 and setId = ?2 and id = ?3")
	List<QuestionnaireSetTopic> getTopicByTypeAndSetIdAndId(String type, String setId, String id);
}